PROJECTENGRAM

[PS] CACHE MEMORY 2

Tags: #◇Computer Science #◇CSARCH2 #◇Cache Memory #◇Computer Architecture #◇Set Associative Mapping #◇Direct Mapping #◇Loop Optimization #◇Cache Thrashing #◇AMAT #◇LRU Replacement


Problem Set: Cache Memory 2

◇Architectural Foundations & Program Execution Analysis

1. Instruction Stream Locality & Block Fetch Dynamics

During sequential and iterative program execution, processor memory references exhibit intense ◇spatial and ◇temporal locality:

  • Spatial Locality in Block Transfers: When an instruction fetch causes a cache miss, the memory controller fetches an entire block (BB words) into cache. The first word incurs the full miss latency (tmisst_{\text{miss}}), while the subsequent B−1B - 1 sequential words within that same block hit the cache (thitt_{\text{hit}}).
  • Temporal Locality in Looping Structures: When a program executes a loop of size LL words, if the loop footprint fits within the cache without thrashing, only the first iteration incurs compulsory misses; all subsequent iterations achieve a 100%100\% hit rate.
『』
TEXT
                  Memory Block (B words)
   ┌──────────┬──────────┬──────────┬──────────┬──────────┐
   │  Word 0  │  Word 1  │  Word 2  │   ...    │ Word B-1 │
   └────┬─────┴────┬─────┴────┬─────┴──────────┴────┬─────┘
        │          │          │                     │
      MISS        HIT        HIT                   HIT
   (Fetch MM)   (Cache)    (Cache)               (Cache)

2. Set Associativity & Working Set Thrashing

In a KK-way set associative cache with SS sets:
Set Index=Block Number(modS)\text{Set Index} = \text{Block Number} \pmod S

  • Working Set Capacity: Each set can hold at most KK distinct blocks concurrently.
  • Set Thrashing (The Pigeonhole Effect): If a tight loop references WW distinct memory blocks that all map to the same set index, and W>KW > K, then under ◇LRU replacement, every block access will cyclically evict the block needed next, reducing the cache hit rate to near zero despite available space in other sets.

3. Timing Models & Performance Equations

  • Memory Access Time Without Cache:
    Tno_cache=Nfetches×tmemT_{\text{no\_cache}} = N_{\text{fetches}} \times t_{\text{mem}}
  • Cache Timing Models:
    • Non-Load-Through / Sequential Architecture:
      thit=tcache,tmiss=tcache+tmemt_{\text{hit}} = t_{\text{cache}}, \quad t_{\text{miss}} = t_{\text{cache}} + t_{\text{mem}}
      Ttotal=(Nword hits×tcache)+(Nword misses×(tcache+tmem))T_{\text{total}} = (N_{\text{word hits}} \times t_{\text{cache}}) + (N_{\text{word misses}} \times (t_{\text{cache}} + t_{\text{mem}}))
      AMAT=TtotalNfetches=tcache+(1−Hword)⋅tmem\text{AMAT} = \frac{T_{\text{total}}}{N_{\text{fetches}}} = t_{\text{cache}} + (1 - H_{\text{word}}) \cdot t_{\text{mem}}
    • Load-Through / Simultaneous Architecture:
      Ttotal=(Nword hits×tcache)+(Nword misses×tmem)T_{\text{total}} = (N_{\text{word hits}} \times t_{\text{cache}}) + (N_{\text{word misses}} \times t_{\text{mem}})
      AMAT=Hword⋅tcache+(1−Hword)⋅tmem\text{AMAT} = H_{\text{word}} \cdot t_{\text{cache}} + (1 - H_{\text{word}}) \cdot t_{\text{mem}}
  • Effective Performance Speedup:
    Speedup=Tno_cacheTwith_cache\text{Speedup} = \frac{T_{\text{no\_cache}}}{T_{\text{with\_cache}}}

◇Problem 6: Set-Associative Execution Trace under Sequential Looping

Problem Statement

A system has a main memory consisting of 1 Mwords1\text{ Mwords} (220 words2^{20}\text{ words}). It possesses a 4K-word4\text{K-word} cache (4096 words4096\text{ words}) organized in a block-set-associative manner with 4 blocks per set4\text{ blocks per set} (K=4K = 4) and 64 words per block64\text{ words per block} (B=64B = 64).

  • Cache access time: tcache=1 nst_{\text{cache}} = 1\text{ ns}
  • Memory access time: tmem=10 nst_{\text{mem}} = 10\text{ ns}
『』
TEXT
+--------------------------------------------------------------------+
| Main Memory: 1 Mwords = 2^20 words (20-bit address)                |
| Cache Capacity: 4 Kwords = 4096 words                              |
| Block Size (B): 64 words = 2^6 words/block                         |
| Associativity (K): 4 blocks/set (4-way Set Associative)            |
| Total Cache Blocks: 4096 / 64 = 64 blocks                          |
| Total Cache Sets (S): 64 / 4 = 16 sets (2^4 sets)                  |
| Timing: t_cache = 1 ns, t_mem = 10 ns                              |
+--------------------------------------------------------------------+

Step-by-Step Solutions

a. Main Memory Address Format

  • Total Main Memory Words: 220 words  ⟹  Address Bits A=20 bits2^{20}\text{ words} \implies \text{Address Bits } A = 20\text{ bits}.
  • WORD Offset Field (w)\text{WORD Offset Field } (w):
    w=log⁡2(64 words/block)=6 bitsw = \log_2(64\text{ words/block}) = \mathbf{6\text{ bits}}
  • Total Cache Blocks:
    C=4096 words64 words/block=64 blocksC = \frac{4096\text{ words}}{64\text{ words/block}} = 64\text{ blocks}
  • Total Cache Sets:
    S=64 blocks4 blocks/set=16 setsS = \frac{64\text{ blocks}}{4\text{ blocks/set}} = 16\text{ sets}
  • SET Index Field (d)\text{SET Index Field } (d):
    d=log⁡2(16 sets)=4 bitsd = \log_2(16\text{ sets}) = \mathbf{4\text{ bits}}
  • TAG Field (t)\text{TAG Field } (t):
    t=A−(d+w)=20−(4+6)=10 bitst = A - (d + w) = 20 - (4 + 6) = \mathbf{10\text{ bits}}

TAG FieldSET Index FieldWORD Offset Field10 bits (Bits [19:10])4 bits (Bits [9:6])6 bits (Bits [5:0])\begin{array}{|c|c|c|} \hline \textbf{TAG Field} & \textbf{SET Index Field} & \textbf{WORD Offset Field} \\ \hline \text{10 bits (Bits [19:10])} & \text{4 bits (Bits [9:6])} & \text{6 bits (Bits [5:0])} \\ \hline \end{array}


b. Total Instruction Fetch Time with NO Cache Memory

  • Sequence Parameters:
    • The processor fetches 4352 words4352\text{ words} from word addresses 0,1,2,…,43510, 1, 2, \dots, 4351 sequentially.
    • The sequence is repeated 9 more times9\text{ more times}, giving a total of:
      Total Iterations=1+9=10 iterations\text{Total Iterations} = 1 + 9 = 10\text{ iterations}
  • Total Word Fetches:
    Ntotal words=4352 words/iteration×10 iterations=43,520 word fetchesN_{\text{total words}} = 4352\text{ words/iteration} \times 10\text{ iterations} = \mathbf{43,520\text{ word fetches}}
  • Execution Time Without Cache:
    Since every word fetch must be serviced directly from main memory at tmem=10 nst_{\text{mem}} = 10\text{ ns}:
    Tno_cache=43,520×10 ns=435,200 ns=435.20 μsT_{\text{no\_cache}} = 43,520 \times 10\text{ ns} = \mathbf{435,200\text{ ns}} = \mathbf{435.20\ \mu\text{s}}

c. Cache Memory Performance with LRU Replacement

1. Working Set & Block Distribution Analysis
  • Total memory blocks spanned per iteration:
    Nblocks/iteration=4352 words64 words/block=68 blocks(Blocks 0 through 67)N_{\text{blocks/iteration}} = \frac{4352\text{ words}}{64\text{ words/block}} = 68\text{ blocks} \quad (\text{Blocks } 0 \text{ through } 67)
  • Mapping function: Set Index=Block Number(mod16)\text{Set Index} = \text{Block Number} \pmod{16}.
  • Distribution of the 68 blocks across the 16 cache sets:
    68=(4×16)+468 = (4 \times 16) + 4
    • Sets 0, 1, 2, and 3 receive 5 blocks each:
  • Set 0: Blocks {0,16,32,48,64}\{0, 16, 32, 48, 64\}
  • Set 1: Blocks {1,17,33,49,65}\{1, 17, 33, 49, 65\}
  • Set 2: Blocks {2,18,34,50,66}\{2, 18, 34, 50, 66\}
  • Set 3: Blocks {3,19,35,51,67}\{3, 19, 35, 51, 67\}
    • Sets 4 through 15 (12 sets12\text{ sets}) receive 4 blocks each:
  • Set 4: Blocks {4,20,36,52}\{4, 20, 36, 52\}
  • Set 5: Blocks {5,21,37,53}\{5, 21, 37, 53\}
  • …\dots
  • Set 15: Blocks {15,31,47,63}\{15, 31, 47, 63\}

2. Iteration-by-Iteration Cache Behavior
A. Sets 4 through 15 (12 Sets ×\times 4 Blocks = 48 Blocks)
  • Since each set capacity is K=4 blocksK = 4\text{ blocks}, all 4 blocks fit simultaneously in the set without eviction.
  • Iteration 1:
    • The 1st word of each block incurs a compulsory miss: 48 block misses48\text{ block misses} (48 word misses48\text{ word misses}).
    • The remaining 63 words63\text{ words} in each block hit: 48×63=3,024 word hits48 \times 63 = 3,024\text{ word hits}.
  • Iterations 2 through 10 (9 iterations9\text{ iterations}):
    • All 48 blocks remain resident in cache.
    • Block misses: 0\mathbf{0}
    • Block hits: 48×9=432 block hits48 \times 9 = \mathbf{432\text{ block hits}}
    • Word hits: 48×64 words×9=27,648 word hits48 \times 64\text{ words} \times 9 = \mathbf{27,648\text{ word hits}}
B. Sets 0 through 3 (4 Sets ×\times 5 Blocks = 20 Blocks)
  • In each set, 5 blocks compete for 4 slots under LRU replacement:
    • Sequence in Set 0: Block 0 →\rightarrow Block 16 →\rightarrow Block 32 →\rightarrow Block 48 →\rightarrow Block 64.
    • Accessing Block 64 evicts the LRU block (Block 0).
    • In the subsequent iteration, when Block 0 is accessed, it misses and evicts Block 16.
    • When Block 16 is accessed, it misses and evicts Block 32, creating a cyclical thrashing loop.
  • Every Iteration (Iterations 1 through 10):
    • All 5 blocks in each of the 4 sets suffer a block miss on their first word access.
    • Block misses per iteration: 4 sets×5 blocks=20 block misses4\text{ sets} \times 5\text{ blocks} = 20\text{ block misses}.
    • Block hits per iteration: 0 block hits\mathbf{0\text{ block hits}}.
    • Word fetches per iteration: 20 word misses20\text{ word misses} (first word of each block) and 20×63=1,260 word hits20 \times 63 = 1,260\text{ word hits}.
  • Total across all 10 Iterations for Sets 0..3:
    • Total block misses: 20×10=200 block misses20 \times 10 = \mathbf{200\text{ block misses}}
    • Total block hits: 0 block hits\mathbf{0\text{ block hits}}
    • Total word misses: 200 word misses200\text{ word misses}
    • Total word hits: 1,260×10=12,600 word hits1,260 \times 10 = \mathbf{12,600\text{ word hits}}

3. Aggregate Performance Metrics (across all 10 iterations)
Block-Level Access Metrics:
  • Total Block Accesses:
    Nblock accesses=68 blocks/iteration×10 iterations=680 block accessesN_{\text{block accesses}} = 68\text{ blocks/iteration} \times 10\text{ iterations} = \mathbf{680\text{ block accesses}}
  • Total Block Misses:
    Nblock misses=Iter 1 (Sets 4..15)+All Iters (Sets 0..3)=48+200=248 block missesN_{\text{block misses}} = \text{Iter 1 (Sets 4..15)} + \text{All Iters (Sets 0..3)} = 48 + 200 = \mathbf{248\text{ block misses}}
  • Total Block Hits:
    Nblock hits=Iters 2..10 (Sets 4..15)=48×9=432 block hitsN_{\text{block hits}} = \text{Iters 2..10 (Sets 4..15)} = 48 \times 9 = \mathbf{432\text{ block hits}}
  • Block Hit Ratio:
    Hblock=432680=63.53%H_{\text{block}} = \frac{432}{680} = \mathbf{63.53\%}
  • Block Miss Ratio:
    Mblock=248680=36.47%M_{\text{block}} = \frac{248}{680} = \mathbf{36.47\%}
Word-Level Instruction Fetch Metrics:
  • Total Word Fetches: 43,520 words43,520\text{ words}
  • Total Word Misses: 248 word misses\mathbf{248\text{ word misses}}
  • Total Word Hits: 43,520−248=43,272 word hits43,520 - 248 = \mathbf{43,272\text{ word hits}}
  • Word Hit Ratio:
    Hword=43,27243,520=99.4301%H_{\text{word}} = \frac{43,272}{43,520} = \mathbf{99.4301\%}
  • Word Miss Ratio:
    Mword=24843,520=0.5699%M_{\text{word}} = \frac{248}{43,520} = \mathbf{0.5699\%}
Total Execution Time & Average Memory Access Time:

Under the non-load-through policy (thit=1 ns,tmiss=1+10=11 nst_{\text{hit}} = 1\text{ ns}, t_{\text{miss}} = 1 + 10 = 11\text{ ns}):
Ttotal=(43,272×1 ns)+(248×11 ns)=43,272+2,728=46,000 ns=46.00 μsT_{\text{total}} = (43,272 \times 1\text{ ns}) + (248 \times 11\text{ ns}) = 43,272 + 2,728 = \mathbf{46,000\text{ ns}} = \mathbf{46.00\ \mu\text{s}}
AMAT=46,000 ns43,520≈1.0570 ns\text{AMAT} = \frac{46,000\text{ ns}}{43,520} \approx \mathbf{1.0570\text{ ns}}

(Under load-through policy: Ttotal=43,272×1+248×10=45,752 ns  ⟹  AMAT≈1.0513 nsT_{\text{total}} = 43,272 \times 1 + 248 \times 10 = 45,752\text{ ns} \implies \text{AMAT} \approx 1.0513\text{ ns})

Performance Comparison:

Speedup over No Cache=435,200 ns46,000 ns≈9.46× faster\text{Speedup over No Cache} = \frac{435,200\text{ ns}}{46,000\text{ ns}} \approx \mathbf{9.46\times \text{ faster}}


◇Problem 7: Direct-Mapped Cache with Nested Looping Architecture

Problem Statement

A program consists of two nested loops executed on a computer with a direct-mapped cache.

  • Main Memory Size: 64 Kwords=216 words64\text{ Kwords} = 2^{16}\text{ words}
  • Cache Size: 1 Kwords=1024 words1\text{ Kwords} = 1024\text{ words}
  • Block Size: 128 words=27 words128\text{ words} = 2^7\text{ words}
  • Memory Access Time: tmem=10 nst_{\text{mem}} = 10\text{ ns}
  • Cache Access Time: tcache=1 nst_{\text{cache}} = 1\text{ ns}
  • Addresses are in decimal word addresses.
『』
TEXT
                  Program Flow Graph & Address Bounds
                  ───────────────────────────────────
                  
                               0 ──┐
                                   │ Straight-line Prologue (1x)
                             127 ──┘
                             128 ──┐
                                   │ 
                             255 ──┘
                             256 ──┐ 
                                   │ │ Inner Loop
                                   │ │ (20x per outer)
                             511 ──┘ 
                             512 ──┐ 
                                   │ │ Outer Loop (10x)
                                   │ │
                            1279 ──┘ 
                            1280 ──┐
                                   │ Straight-line Epilogue (1x)
                            1535 ──┘

Step-by-Step Solutions

a. Main Memory Address Field Partitioning

  • Main Memory Words: 64 Kwords=216 words  ⟹  Address Bits A=16 bits64\text{ Kwords} = 2^{16}\text{ words} \implies \text{Address Bits } A = 16\text{ bits}.
  • WORD Offset Field (w)\text{WORD Offset Field } (w):
    w=log⁡2(128 words/block)=7 bitsw = \log_2(128\text{ words/block}) = \mathbf{7\text{ bits}}
  • Total Cache Blocks:
    C=1024 words128 words/block=8 blocks(Lines 0 through 7)C = \frac{1024\text{ words}}{128\text{ words/block}} = 8\text{ blocks} \quad (\text{Lines } 0 \text{ through } 7)
  • BLOCK Index Field (s)\text{BLOCK Index Field } (s):
    s=log⁡2(8 cache blocks)=3 bitss = \log_2(8\text{ cache blocks}) = \mathbf{3\text{ bits}}
  • TAG Field (t)\text{TAG Field } (t):
    t=A−(s+w)=16−(3+7)=6 bitst = A - (s + w) = 16 - (3 + 7) = \mathbf{6\text{ bits}}

TAG FieldBLOCK Index FieldWORD Offset Field6 bits (Bits [15:10])3 bits (Bits [9:7])7 bits (Bits [6:0])\begin{array}{|c|c|c|} \hline \textbf{TAG Field} & \textbf{BLOCK Index Field} & \textbf{WORD Offset Field} \\ \hline \text{6 bits (Bits [15:10])} & \text{3 bits (Bits [9:7])} & \text{7 bits (Bits [6:0])} \\ \hline \end{array}


Memory Block Mapping Table

Each block contains 128 words (MM Block Number B=⌊Address/128⌋\text{MM Block Number } B = \lfloor \text{Address} / 128 \rfloor):

Address RangeBlock Number (BB)Direct Cache Line (B(mod8)B \pmod 8)Code Section Description
0−1270 - 127Block 0Line 0Straight-line Prologue (1×1\times)
128−255128 - 255Block 1Line 1Outer Loop Header (10×10\times)
256−383256 - 383Block 2Line 2Inner Loop Body (20×20\times per outer)
384−511384 - 511Block 3Line 3Inner Loop Body (20×20\times per outer)
512−639512 - 639Block 4Line 4Outer Loop Body (10×10\times)
640−767640 - 767Block 5Line 5Outer Loop Body (10×10\times)
768−895768 - 895Block 6Line 6Outer Loop Body (10×10\times)
896−1023896 - 1023Block 7Line 7Outer Loop Body (10×10\times)
1024−11511024 - 1151Block 8Line 0Outer Loop Body (10×10\times, maps to Line 0)
1152−12791152 - 1279Block 9Line 1Outer Loop Body (10×10\times, maps to Line 1)
1280−14071280 - 1407Block 10Line 2Straight-line Epilogue (1×1\times, maps to Line 2)
1408−15351408 - 1535Block 11Line 3Straight-line Epilogue (1×1\times, maps to Line 3)

b. Execution Trace & Performance Calculations

1. Phase-by-Phase Execution Analysis
Phase 1: Straight-Line Prologue (0−1270 - 127)
  • Access Block 0 (Line 0): Line 0 is empty   ⟹  \implies 1 Block Miss, 0 Block Hits.
  • Line 0 loaded with Block 0.
Phase 2: Outer Loop Iteration 1
  1. Access Block 1 (Line 1): Empty   ⟹  \implies Miss (Line 1 = Block 1).
  2. Inner Loop (20 iterations of Blocks 2 and 3):
    • Inner Iteration 1:
  • Block 2 (Line 2): Empty   ⟹  \implies Miss (Line 2 = Block 2).
  • Block 3 (Line 3): Empty   ⟹  \implies Miss (Line 3 = Block 3).
    • Inner Iterations 2 through 20 (19 iterations):
  • Block 2: Present in Line 2   ⟹  \implies 19 Hits.
  • Block 3: Present in Line 3   ⟹  \implies 19 Hits.
  1. Outer Loop Remaining Blocks (512−1279512 - 1279):
    • Block 4 (Line 4): Empty   ⟹  \implies Miss (Line 4 = Block 4).
    • Block 5 (Line 5): Empty   ⟹  \implies Miss (Line 5 = Block 5).
    • Block 6 (Line 6): Empty   ⟹  \implies Miss (Line 6 = Block 6).
    • Block 7 (Line 7): Empty   ⟹  \implies Miss (Line 7 = Block 7).
    • Block 8 (Line 0): Line 0 contains Block 0   ⟹  \implies Miss (Conflict) (Line 0 = Block 8).
    • Block 9 (Line 1): Line 1 contains Block 1   ⟹  \implies Miss (Conflict) (Line 1 = Block 9).
  • Iteration 1 Subtotal:
    • Block Misses: 1 (Blk 1)+2 (Blks 2,3)+4 (Blks 4..7)+2 (Blks 8,9)=9 block misses1\text{ (Blk 1)} + 2\text{ (Blks 2,3)} + 4\text{ (Blks 4..7)} + 2\text{ (Blks 8,9)} = \mathbf{9\text{ block misses}}
    • Block Hits: 19+19=38 block hits19 + 19 = \mathbf{38\text{ block hits}}
    • Total Block Accesses in Iter 1: 1+(20×2)+6=47 block accesses1 + (20 \times 2) + 6 = \mathbf{47\text{ block accesses}}

Cache State at End of Outer Iteration 1:
Line 0Line 1Line 2Line 3Line 4Line 5Line 6Line 7Block 8Block 9Block 2Block 3Block 4Block 5Block 6Block 7\begin{array}{|c|c|c|c|c|c|c|c|} \hline \textbf{Line 0} & \textbf{Line 1} & \textbf{Line 2} & \textbf{Line 3} & \textbf{Line 4} & \textbf{Line 5} & \textbf{Line 6} & \textbf{Line 7} \\ \hline \text{Block 8} & \text{Block 9} & \text{Block 2} & \text{Block 3} & \text{Block 4} & \text{Block 5} & \text{Block 6} & \text{Block 7} \\ \hline \end{array}


Phase 3: Outer Loop Iterations 2 through 10 (9 Iterations)

In each of the remaining 9 iterations:

  1. Access Block 1 (Line 1): Line 1 currently contains Block 9   ⟹  \implies Miss (Conflict). Line 1 is overwritten with Block 1.
  2. Inner Loop (20 iterations of Blocks 2 and 3):
    • Blocks 2 and 3 are resident in Lines 2 and 3 and were never overwritten!
    • All 20 accesses to Block 2   ⟹  \implies 20 Hits.
    • All 20 accesses to Block 3   ⟹  \implies 20 Hits.
  3. Outer Loop Remaining Blocks:
    • Block 4 (Line 4): Resident   ⟹  \implies 1 Hit.
    • Block 5 (Line 5): Resident   ⟹  \implies 1 Hit.
    • Block 6 (Line 6): Resident   ⟹  \implies 1 Hit.
    • Block 7 (Line 7): Resident   ⟹  \implies 1 Hit.
    • Block 8 (Line 0): Resident (Line 0 holds Block 8)   ⟹  \implies 1 Hit.
    • Block 9 (Line 1): Line 1 contains Block 1   ⟹  \implies Miss (Conflict). Line 1 is overwritten with Block 9.
  • Per-Iteration Subtotal (Iter 2..10):
    • Block Misses per iteration: 2 misses\mathbf{2\text{ misses}} (Block 1 and Block 9)
    • Block Hits per iteration: 20+20+1+1+1+1+1=45 hits20 + 20 + 1 + 1 + 1 + 1 + 1 = \mathbf{45\text{ hits}}
  • Subtotal across Iterations 2 through 10 (9 iterations):
    • Block Misses: 9×2=18 block misses9 \times 2 = \mathbf{18\text{ block misses}}
    • Block Hits: 9×45=405 block hits9 \times 45 = \mathbf{405\text{ block hits}}
    • Block Accesses: 9×47=423 block accesses9 \times 47 = \mathbf{423\text{ block accesses}}

Phase 4: Straight-Line Epilogue (1280−15351280 - 1535)
  • Access Block 10 (Line 2): Line 2 contains Block 2   ⟹  \implies Miss (Conflict) (Line 2 = Block 10).
  • Access Block 11 (Line 3): Line 3 contains Block 3   ⟹  \implies Miss (Conflict) (Line 3 = Block 11).
  • Epilogue Subtotal: 2 Block Misses, 0 Block Hits.

2. Grand Totals & Performance Metrics
A. Block-Level Statistics
  • Total Block Accesses:
    Nblock accesses=1 (prologue)+47 (iter 1)+423 (iters 2..10)+2 (epilogue)=473 block accessesN_{\text{block accesses}} = 1\text{ (prologue)} + 47\text{ (iter 1)} + 423\text{ (iters 2..10)} + 2\text{ (epilogue)} = \mathbf{473\text{ block accesses}}
  • Total Block Misses:
    Nblock misses=1+9+18+2=30 block missesN_{\text{block misses}} = 1 + 9 + 18 + 2 = \mathbf{30\text{ block misses}}
  • Total Block Hits:
    Nblock hits=0+38+405+0=443 block hitsN_{\text{block hits}} = 0 + 38 + 405 + 0 = \mathbf{443\text{ block hits}}
  • Block Hit Rate:
    Hblock=443473≈93.6575%H_{\text{block}} = \frac{443}{473} \approx \mathbf{93.6575\%}
  • Block Miss Rate:
    Mblock=30473≈6.3425%M_{\text{block}} = \frac{30}{473} \approx \mathbf{6.3425\%}

B. Word-Level Statistics
  • Total Word Fetches:
    Nwords=473 block accesses×128 words/block=60,544 wordsN_{\text{words}} = 473\text{ block accesses} \times 128\text{ words/block} = \mathbf{60,544\text{ words}}
  • Total Word Misses:
    Each block miss results in exactly 1 word miss (the first word requested, which triggers the 128-word block refill):
    Nword misses=30 word missesN_{\text{word misses}} = \mathbf{30\text{ word misses}}
  • Total Word Hits:
    Nword hits=60,544−30=60,514 word hitsN_{\text{word hits}} = 60,544 - 30 = \mathbf{60,514\text{ word hits}}
    (Composed of 443×128=56,704 hits443 \times 128 = 56,704\text{ hits} from block hits + 30×127=3,810 hits30 \times 127 = 3,810\text{ hits} from spatial locality within missed blocks)
  • Word Hit Rate:
    Hword=60,51460,544≈99.9504%H_{\text{word}} = \frac{60,514}{60,544} \approx \mathbf{99.9504\%}
  • Word Miss Rate:
    Mword=3060,544≈0.0496%M_{\text{word}} = \frac{30}{60,544} \approx \mathbf{0.0496\%}

C. Total Execution Time & Average Memory Access Time

Under the non-load-through policy (tcache=1 ns,tmem=10 ns  ⟹  tmiss=11 nst_{\text{cache}} = 1\text{ ns}, t_{\text{mem}} = 10\text{ ns} \implies t_{\text{miss}} = 11\text{ ns}):
Ttotal=(60,514×1 ns)+(30×11 ns)=60,514+330=60,844 ns=60.844 μsT_{\text{total}} = (60,514 \times 1\text{ ns}) + (30 \times 11\text{ ns}) = 60,514 + 330 = \mathbf{60,844\text{ ns}} = \mathbf{60.844\ \mu\text{s}}
AMAT=60,844 ns60,544≈1.004955 ns≈1.0050 ns\text{AMAT} = \frac{60,844\text{ ns}}{60,544} \approx \mathbf{1.004955\text{ ns}} \approx \mathbf{1.0050\text{ ns}}

(Under load-through policy: Ttotal=60,514×1+30×10=60,814 ns  ⟹  AMAT≈1.0045 nsT_{\text{total}} = 60,514 \times 1 + 30 \times 10 = 60,814\text{ ns} \implies \text{AMAT} \approx 1.0045\text{ ns})


Master Execution Summary Table for Problem 7

Program PhaseIterationsBlock AccessesBlock MissesBlock HitsWord MissesWord HitsPhase Time (ns)
Prologue (0–127)11101127138
Outer Loop Iter 114793896,0076,106
Outer Loop Iters 2–109423184051854,12654,324
Epilogue (1280–1535)12202254276
Grand Total—473304433060,51460,844

◇Key Architectural Insights & Performance Analysis

  1. The Role of Spatial Locality in Loop Structures:

    • Even when block hit rates are around 93.66%93.66\%, the word hit rate exceeds 99.95%99.95\% because a single 128-word block fetch provides 127 consecutive cache hits.
    • Increasing block size amortizes miss penalties across larger sequential instruction runs.
  2. Conflict Miss Dynamics:

    • In Problem 7, the outer loop references 9 distinct blocks (Blocks 1 through 9) on an 8-line direct-mapped cache.
    • The conflict occurs strictly between Block 1 and Block 9, both mapping to Line 1.
    • If the cache were 2-way set associative with the same capacity (4 sets of 2 lines), Blocks 1 and 9 would coexist in Set 1 without eviction, eliminating all 18 conflict misses in iterations 2 through 10.
  3. Compiler and Software Optimization Strategies:

    • Loop Alignment: Aligning loop entry points to cache line boundaries prevents loops from straddling unnecessary line boundaries.
    • Code Reordering / Loop Splitting: Restructuring code so that concurrent working sets do not alias to the same cache sets eliminates thrashing.

◇References & Navigation

[PS] Cache Memory 2 | PROJECT ENGRAM